package duck.dao.impl;

import java.util.List;

import common.CommonDao;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Element;

import org.json.simple.*;

import pojo.Messagetype;
import duck.dao.MessageDao;

public class MessageDaoImpl implements MessageDao {
	private CommonDao cd=factory.DaoFactory.getCommonDao();
	
	public String getAllMessageTypes() {
		try {
		
				JSONArray array=new JSONArray();
				List<Messagetype > types=cd.loadAll("Messagetype");
				for(Messagetype t:types){
					JSONObject obj=new JSONObject();
					obj.put("text", t.getMname());
					obj.put("value",t.getMtypeId());
					array.add(obj);
				}
			
			return array.toJSONString();
			
		}  catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}


}
